package com.wzdigit.wms.wms.service.core.asn;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.wzdigit.wms.basic.domain.asn.AsnDtl;
import com.wzdigit.wms.basic.mapper.core.order.AsnDtlMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;


/**
 * <p>
 * 收货通知单明细 服务类
 * </p>
 *
 * @author
 * @since 2021-01-12
 */
@Service
@Slf4j
public class AsnDtlService {

    @Autowired
    AsnDtlMapper asnDtlMapper;

    public AsnDtlMapper getMapper() {
        return asnDtlMapper;
    }

    /**
     * 根据入参实体，新增一条记录
     *
     * @param asnDtl
     * @return
     */
    @Transactional(rollbackFor = Exception.class, propagation = Propagation.REQUIRED)
    public AsnDtl addNewOne(AsnDtl asnDtl) {

        int row = asnDtlMapper.insert(asnDtl);
        log.info("成功新增{}条记录", row);

        return asnDtl;
    }

    /**
     * 根据入参更新
     *
     * @param asnDtl
     * @return
     */
    public AsnDtl updateOne(AsnDtl asnDtl) {

        int row = asnDtlMapper.updateById(asnDtl);
        log.info("成功更新{}条记录", row);
        return asnDtl;
    }

    /**
     * 根据送检单 获取 收货单明细信息
     *
     * @param billNo
     * @return
     */
    public AsnDtl selectOneByInspNo(String billNo) {
        QueryWrapper<AsnDtl> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("INSP_NO", billNo);
        return this.asnDtlMapper.selectOne(queryWrapper);

    }

    /**
     * 根据收货单 获取 收货单明细信息
     *
     * @param billNo
     * @return
     */
    public List<AsnDtl> selectListByAsnNo(String billNo) {
        QueryWrapper<AsnDtl> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("ASN_NO", billNo);
        return this.asnDtlMapper.selectList(queryWrapper);
    }

    /**
     * 根据明细行ID,获取收货单明细信息
     *
     * @param ids
     * @return
     */
    public List<AsnDtl> selectListByIds(List<Integer> ids) {
        QueryWrapper<AsnDtl> queryWrapper = new QueryWrapper<>();
        queryWrapper.in("ASN_DTL_ID", ids);
        return this.asnDtlMapper.selectList(queryWrapper);
    }

}
